//JavaScript Framework 2.0 Code
try {
    Type.registerNamespace('com.yonyou.ncmm_pac_pda.TransInScanController');
    com.yonyou.ncmm_pac_pda.TransInScanController = function () {
        com.yonyou.ncmm_pac_pda.TransInScanController.initializeBase(this);
        this.initialize();
    }

    function com$yonyou$ncmm_pac_pda$TransInScanController$initialize() {
        //you can programing by $ctx API
        //get the context data through $ctx.get()
        //set the context data through $ctx.push(json)
        //set the field of the context through $ctx.put(fieldName, fieldValue)
        //get the parameter of the context through $ctx.param(parameterName)
        //Demo Code:
        //    var str = $ctx.getString();      //获取当前Context对应的字符串
        //    alert($ctx.getString())          //alert当前Context对应的字符串
        //    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
        //    json["x"] = "a";        //为当前json增加字段
        //    json["y"] = [];           //为当前json增加数组
        //    $ctx.push(json);            //设置context，并自动调用数据绑定
        //
        //    put方法需手动调用databind()
        //    var x = $ctx.get("x");    //获取x字段值
        //    $ctx.put("x", "b");     //设置x字段值
        //    $ctx.put("x", "b");     //设置x字段值
        //    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
        //    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
        //    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
        //    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组

        //your initialize code below...

    }

    function com$yonyou$ncmm_pac_pda$TransInScanController$evaljs(js) {
        eval(js)
    }

//加载
    function com$yonyou$ncmm_pac_pda$TransInScanController$onload(sender, args) {
        var row = $param.getJSONObject("row");
        row = NCMMPubUtil.htmlspecialjson2UI(row);
        // 如果不存在数据表则先创建
        NCMMPubUtil.createTable(TransInScanVO);
        if (!(row == null || row == "")) {
            var json = {};
            json = row;
            editVbatchcode = json.vbatchcode;
            $ctx.push(json);
            $ctx.dataBind();
        }
    }

//下拉菜单
    function opendropmenu(sender, args) {
        TransInUtil.openDropDownList("btn_menu");
    }

//手工录入条码或者pda红外扫码
    function com$yonyou$ncmm_pac_pda$TransInScanController$inputMarCode(sender, args) {
        marScanBack();
    }

//扫物料码
    function com$yonyou$ncmm_pac_pda$TransInScanController$doscan(sender, args) {
        var listJson = $ctx.getJSONObject();
        if (NCMMPubUtil.isEmpty(listJson.cgeneralhid)) {
            $alert("请先指定单据！");
            return;
        }
        $scanner.open({
            bindfield: "marbarcode",
            callback: "marScanBack()"
        });
    }

    function marScanBack() {
        var marbarcode = $ctx.getString("marbarcode");
        if (marbarcode != null && marbarcode != "") {
            $id("textbox0").set("value", marbarcode);
            $ctx.dataBind();
        }
        parseMarCode(marbarcode);
        $id("textbox0").set("value", null);
        $id("textbox0").focus();
    }

    //解析条码
    function parseMarCode(marbarcode) {
        var listJson = $ctx.getJSONObject();
        if (NCMMPubUtil.isEmpty(listJson.cgeneralhid)) {
            $alert("请先指定单据号！");
            return;
        }
        if (NCMMPubUtil.isEmpty(marbarcode)) {
            $alert("物料码为空！");
            return;
        }
        var marJson = NCMMBarcodeParseUtil.parseMaterialBar(marbarcode);

        //判断是否为出箱 出箱返回的是数组
        if (Array.isArray(marJson)){
            let succeedNum = 0;
            for(let i = 0; i < marJson.length; i++) {
                let succeed = parseMarCodeNext(marJson[i],listJson);
                if (succeed == true){
                    succeedNum++;
                }
            }
            $alert("成功扫描【" + succeedNum +"】条数据！");
        }else {
            parseMarCodeNext(marJson,listJson);
        }
    }


    function parseMarCodeNext(marJson, listJson) {
        var marID = marJson.pk_material;
        if (NCMMPubUtil.isEmpty(marID)) {
            $alert(marJson.failmsg);
            return;
        }
        if (!NCMMPubUtil.isEmpty(listJson.cgeneralbid)) {
            var wheresql = " where cgeneralbid='" + listJson.cgeneralbid + "'";
            NCMMPubUtil.queryVO(TransInVO, wheresql, function (data) {
                if (typeof (data) == 'undefined' || data == null || data.length == 0) {
                    return;
                } else {
                    var vos = eval(data);
                    vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
                    if (vos != null && vos.length > 0) {
                        listJson = vos[0];
                    }
                }
            });
        }
        if (NCMMPubUtil.isEmpty(listJson.cgeneralhid) || marID != listJson.cmaterialvid || marJson.vbatchcode != listJson["vbatchcode"]) {
            var vo = queryScanInfo(marID, marJson.vbatchcode, listJson.cgeneralhid);
            if (NCMMPubUtil.isEmpty(vo)) {
                $alert("扫描物料" + marJson.code + "不在对应的单据" + listJson["vbillcode"] + "中");
                return;
            }
            listJson = vo;
        }
        //扫描的批次号与单据本身的批次号均不空且不同为true
        var isNotEditAndBatchcodeDif = NCMMPubUtil.isNotEmpty(listJson["vbatchcode"]) && NCMMPubUtil.isNotEmpty(marJson.vbatchcode) && listJson["vbatchcode"] != marJson.vbatchcode;
        if (isNotEditAndBatchcodeDif) {
            $alert("扫描物料" + marJson.code + "的批次号和单据" + listJson["vbillcode"] + "的批次号不符！");
            return;
        }
        if (NCMMPubUtil.isNotEmpty(marJson.vbatchcode)) {
            listJson["vbatchcode"] = marJson.vbatchcode;
            listJson["pk_batchcode"] = marJson.pk_batch;
        }
        listJson["vserialcode"] = marJson.vserialcode;
        var num = 1;
        var vchangerate = listJson["vchangerate"];
        var nastnum = TransInUtil.getAstnum(1, vchangerate);
        if (NCMMPubUtil.isNotEmpty(marJson.nnum)) {
            num = marJson.nnum;
            nastnum = TransInUtil.getAstnum(num, vchangerate);
        } else if (NCMMPubUtil.isNotEmpty(marJson.nassistnum)) {
            nastnum = marJson.nassistnum;
            num = TransInUtil.getNum(nastnum, vchangerate);
        }
        var unitBitNum = TransInUtil.getUnitBitnumber(listJson["cunitid"]);
        if (!NCMMPubUtil.isEmpty(unitBitNum)) {
            num = num.toFixed(unitBitNum);
        }
        var astunitBitNum = TransInUtil.getUnitBitnumber(listJson["castunitid"]);
        if (!NCMMPubUtil.isEmpty(astunitBitNum)) {
            nastnum = TransInUtil.decimalPrecision(nastnum, astunitBitNum);
        }
        listJson["nscannum"] = num;
        listJson["nscanastnum"] = nastnum;
        listJson["pk_transinscan"] = getTransScanInPK();
        NCMMPubUtil.insertVO(TransInScanVO, listJson);
        TransInUtil.updateTransInScanedNum(listJson.cgeneralbid);
        $ctx.push(listJson);
        $ctx.dataBind();
        return true;
    }


    function getTransScanInPK() {
        var date = new Date().getTime();
        var pk = "4007" + date.toString() + "222";
        return pk;
    }

//查询扫描信息
    function queryScanInfo(marID, vbatchcode, cgeneralhid) {
        var vo = {};
        var whereSql = " where cgeneralhid='" + cgeneralhid + "' and cmaterialvid='" + marID + "'";
        NCMMPubUtil.queryVO(TransInVO, whereSql, function (data) {
            if (typeof (data) == 'undefined' || data == null || data.length == 0) {
                vo = null;
            } else {
                var vos = eval(data);
                vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
                if (vos != null && vos.length > 0) {
                    if (vos.length == 1) {
                        vo = vos[0];
                    } else {
                        vo = getScanVO(vos, vbatchcode);
                    }
                } else {
                    vo = null;
                }
            }
        });
        return vo;
    }

    function getScanVO(vos, vbatchcode) {
        //数量满足批次号为空的行，或当扫描物料的批次号为空时，数量不满足的行
        var result1 = [];
        //数量不满足批次号相同的行
        var result2 = [];
        //数量不满足批次号为空的行
        var result3 = [];
        //数量满足批次号不一致的行
        var result4 = [];
        //数量不满足批次不一致的行
        var result5 = [];
        var vo = {};
        for (var i = 0; i < vos.length; i++) {
            //数量满足
            if (vos[i].nnum > vos[i].nscanednum) {
                if (NCMMPubUtil.isEmpty(vbatchcode)) {
                    return vos[i];
                } else if (vbatchcode == vos[i].vbatchcode) {
                    return vos[i];
                } else if (NCMMPubUtil.isEmpty(vos[i].vbatchcode)) {
                    result1.push(vos[i]);
                } else {
                    result4.push(vos[i]);
                }
            }
            //数量不满足
            else {
                if (NCMMPubUtil.isEmpty(vbatchcode)) {
                    result1.push(vos[i]);
                } else if (vbatchcode == vos[i].vbatchcode) {
                    result2.push(vos[i]);
                } else if (NCMMPubUtil.isEmpty(vos[i].vbatchcode)) {
                    result3.push(vos[i]);
                } else {
                    result5.push(vos[i]);
                }
            }
        }
        if (result1.length > 0) {
            return result1[0];
        } else if (result2.length > 0) {
            return result2[0];
        } else if (result3.length > 0) {
            return result3[0];
        } else if (result4.length > 0) {
            return result4[0];
        } else if (result5.length > 0) {
            return result5[0];
        } else {
            return null;
        }
    }

    function com$yonyou$ncmm_pac_pda$TransInScanController$close(sender, args) {
        $view.close();
    }

//修改辅数量时计算主数量
    function com$yonyou$ncmm_pac_pda$TransInScanController$calNum(sender, args) {
        var nn = args["newvalue"];
        if (NCMMPubUtil.isEmpty(nn)) {
            $ctx.put("nscannum", "");
            $ctx.dataBind();
            return;
        }
        if (nn == "-") {
            return;
        }
        if (!$.isNumeric(nn)) {
            $ctx.put("nscanastnum", args["oldvalue"]);
            $ctx.dataBind();
            return;
        }
        if (TransInUtil.isBsBitnumber(nn, $ctx.getString("castunitid"))) {
            $ctx.put("nscanastnum", args["oldvalue"]);
            $ctx.dataBind();
            return;
        }
        $ctx.dataCollect();
        var nastnum = $ctx.getString("nscanastnum");
        if (NCMMPubUtil.isEmpty(nastnum)) {
            //辅数量输入为空
            $ctx.put("nscannum", "");
            $ctx.dataBind();
            return;
        }
        if (!$.isNumeric(nastnum)) {
            $alert("扫描数量输入不合法！");
            return;
        }
        var vchangerate = $ctx.getString("vchangerate");
        var nnum;
        if (!NCMMPubUtil.isEmpty(nastnum)) {
            nnum = TransInUtil.getNum(nastnum, vchangerate);
            var bitnum = TransInUtil.getUnitBitnumber($ctx.getString("cunitid"));
            if (!NCMMPubUtil.isEmpty(bitnum)) {
                nnum = TransInUtil.decimalPrecision(nnum, bitnum);
            }
            if (nnum.toString() == "NaN") {
                $alert("数量输入不合法！");
                return;
            }
        }
        $ctx.put("nscannum", nnum);
        $ctx.dataBind();
    }

//修改主数量时计算辅数量
    function com$yonyou$ncmm_pac_pda$TransInScanController$calAstNum(sender, args) {
        var nn = args["newvalue"];
        if (NCMMPubUtil.isEmpty(nn)) {
            $ctx.put("nscanastnum", "");
            $ctx.dataBind();
            return;
        }
        if (nn == "-") {
            return;
        }
        if (!$.isNumeric(nn)) {
            $ctx.put("nscannum", args["oldvalue"]);
            $ctx.dataBind();
            return;
        }
        if (TransInUtil.isBsBitnumber(nn, $ctx.getString("cunitid"))) {
            $ctx.put("nscannum", args["oldvalue"]);
            $ctx.dataBind();
            return;
        }
        $ctx.dataCollect();
        var nnum = $ctx.getString("nscannum");
        if (NCMMPubUtil.isEmpty(nnum)) {
            //主数量输入为空
            $ctx.put("nscanastnum", "");
            $ctx.dataBind();
            return;
        }
        if (!$.isNumeric(nnum)) {
            $alert("扫描主数量输入不合法！");
            return;
        }
        var vchangerate = $ctx.getString("vchangerate");
        var nastnum = "";
        if (!NCMMPubUtil.isEmpty(nnum)) {
            nastnum = TransInUtil.getAstnum(nnum, vchangerate);
            var bitnum = TransInUtil.getUnitBitnumber($ctx.getString("castunitid"));
            if (!NCMMPubUtil.isEmpty(bitnum)) {
                nastnum = TransInUtil.decimalPrecision(nastnum, bitnum);
            }
            if (nastnum.toString() == "NaN") {
                $alert("数量输入不合法！");
                return;
            }
        }
        $ctx.put("nscanastnum", nastnum);
        $ctx.dataBind();
    }

//保存
    function com$yonyou$ncmm_pac_pda$TransInScanController$saveScanInfo(sender, args) {
        var json = $ctx.getJSONObject();
        if (json.nscannum == null || json.nscannum == 0 || json.nscannum == "0") {
            $alert("扫描主数量不能为空或0！");
            return;
        }
        if (json.nscanastnum == null || json.nscanastnum == 0 || json.nscanastnum == "0") {
            $alert("扫描数量不能为空或0！");
            return;
        }
        if (!$.isNumeric(json.nscannum) || !$.isNumeric(json.nscanastnum)) {
            $alert("数量输入不合法！");
            return;
        }
        json = NCMMPubUtil.htmlspecialjson2UI(json);
        var isSuccess = doSave(json);
        if (isSuccess == true) {
            $toast("保存成功！");
        }
    }

//保存按钮保存或提交前保存
    function doSave(json) {
        //if (NCMMPubUtil.isEmpty(json["vbatchcode"])) {
        json["pk_batchcode"] = "";
        //} else {
        /** 去掉批次档案
         var sql = " where vbatchcode='" + json["vbatchcode"] + "' and cmaterialvid='" + json["cmaterialvid"] + "'";
         var pk_batchcode = "";
         if(NCMMPubUtil.isTableExist(BatchcodeVO) ){
            NCMMPubUtil.queryVO(BatchcodeVO, sql, function(data) {
                if(typeof(data) == 'undefined' || data == null || data.length == 0) {
                    return;
                } else {
                    var vos = eval(data);
                    if(vos != null && vos.length > 0) {
                        pk_batchcode = vos[0].pk_batchcode;
                    }
                }
            });
        }
         if(NCMMPubUtil.isEmpty(pk_batchcode)) {
            json["pk_batchcode"] = "";
            $alert("批次号不在批次档案中，请检查输入或更新批次档案！");
            return false;
        }
         json["pk_batchcode"] = pk_batchcode;
         */
            //}
        var billBatchCode = getBillBatchCode(json["cgeneralbid"]);
        if (NCMMPubUtil.isEmpty(json["pk_transinscan"])) {
            if (!NCMMPubUtil.isEmpty(json["vbatchcode"]) && !NCMMPubUtil.isEmpty(billBatchCode) && json["vbatchcode"] != billBatchCode) {
                $alert("扫描物料" + json["cmaterialvid_name"] + "的批次号和单据" + json["vbillcode"] + "的批次号不符！");
                return false;
            }
            json["pk_transinscan"] = getTransScanInPK();
            NCMMPubUtil.insertVO(TransInScanVO, json);
            $ctx.push(json);
            $ctx.dataBind();
        } else {
            var oldBatchCode = getScanBatchCode(json["pk_transinscan"]);
            if (!NCMMPubUtil.isEmpty(json["vbatchcode"]) && !NCMMPubUtil.isEmpty(billBatchCode) && json["vbatchcode"] != oldBatchCode && json["vbatchcode"] != billBatchCode) {
                $alert("扫描物料" + json["cmaterialvid_name"] + "的批次号和单据" + json["vbillcode"] + "的批次号不符！");
                return false;
            }
            NCMMPubUtil.updateVO(TransInScanVO, json);
            $ctx.push(json);
            $ctx.dataBind();
        }
        //更新列表扫描数量
        TransInUtil.updateTransInScanedNum(json.cgeneralbid);
        return true;
    }

//查询记录内批次号
    function getScanBatchCode(pk_transinscan) {
        var sql = " where pk_transinscan='" + pk_transinscan + "'";
        var batchcode = "";
        NCMMPubUtil.queryVO(TransInScanVO, sql, function (data) {
            if (typeof (data) == 'undefined' || data == null || data.length == 0) {
                return;
            } else {
                var vos = eval(data);
                vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
                if (vos != null && vos.length > 0) {
                    batchcode = vos[0].vbatchcode;
                }
            }
        });
        return batchcode;
    }

//查询批次号
    function getBillBatchCode(cgeneralbid) {
        var sql = " where cgeneralbid='" + cgeneralbid + "'";
        var batchcode = "";
        NCMMPubUtil.queryVO(TransInVO, sql, function (data) {
            if (typeof (data) == 'undefined' || data == null || data.length == 0) {
                return;
            } else {
                var vos = eval(data);
                vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
                if (vos != null && vos.length > 0) {
                    batchcode = vos[0].vbatchcode;
                }
            }
        });
        return batchcode;
    }

    function com$yonyou$ncmm_pac_pda$TransInScanController$doCommit(sender, args) {
        var json = $ctx.getJSONObject();
        var stordoc = $cache.read("defaultstordoc");
        //默认仓库和调入仓库均为空
        if (NCMMPubUtil.isEmpty(stordoc) && NCMMPubUtil.isEmpty(json.cotherwhid)) {
            $alert("默认仓库不能为空，请设置！");
            return;
        }
        if (NCMMPubUtil.isEmpty(json.cgeneralbid)) {
            $alert("无扫描数据，不能提交！");
            return;
        }
        if (json.nscannum == null || json.nscannum == 0 || json.nscannum == "0") {
            $alert("扫描主数量不能为空或0！")
            return;
        }
        if (json.nscanastnum == null || json.nscanastnum == 0 || json.nscanastnum == "0") {
            $alert("扫描数量不能为空或0！")
            return;
        }
        if (!$.isNumeric(json.nscannum) || !$.isNumeric(json.nscanastnum)) {
            $alert("数量输入不合法！")
            return;
        }
        json = NCMMPubUtil.htmlspecialjson2UI(json);
        var isSuccess = doSave(json);
        if (isSuccess == false) {
            return;
        }
        var scanNum = TransInUtil.getScanVOCount(json.cgeneralbid);
        if (scanNum > 1) {
            $js.hideLoadingBar();
            $alert("当前单据行有其他扫描记录，请全部选中后再提交！");
            return;
        }
        var sql = " where pk_transinscan='" + json.pk_transinscan + "'";
        var vo = {};
        NCMMPubUtil.queryVO(TransInScanVO, sql, function (scanData) {
            if (typeof (scanData) == 'undefined' || scanData == null || scanData.length == 0) {
                return;
            }
            var vos = eval(scanData);
            vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
            vo = vos[0];
        });
        if (NCMMPubUtil.isEmpty(vo)) {
            $alert("当前扫描记录已经被删除，不能提交！")
            return;
        }
        //组件提交billinfos
        var head = {};
        head["csourcebillhid"] = vo.cgeneralhid;
        //如果默认仓库不为空取默认仓库，否则取单据上的调入仓库
        if (NCMMPubUtil.isEmpty(stordoc) || NCMMPubUtil.isEmpty($stringToJSON(stordoc).pk_stordoc)) {
            head["cwarehouseid"] = vo.cotherwhid;
        } else {
            head["cwarehouseid"] = $stringToJSON(stordoc).pk_stordoc;
        }
        head["ts_h"] = vo.hts;
        var item = {};
        item["csourcebillbid"] = vo.cgeneralbid;
        item["cmaterialvid"] = vo.cmaterialvid;
        item["castunitid"] = vo.castunitid;
        item["nscannum"] = vo.nscannum;
        item["nscanastnum"] = vo.nscanastnum;
        //item["pk_batchcode"] = vo.pk_batchcode;
        item["vbatchcode"] = vo.vbatchcode;
        item["ts_b"] = vo.bts;
        if (!NCMMPubUtil.isEmpty(vo.vserialcode) || !NCMMPubUtil.isEmpty(vo.cinspaceid)) {
            var bbitem = {};
            //bbitem["pk_serialcode"] = vo.pk_serialcode;
            bbitem["vserialcode"] = vo.vserialcode;
            bbitem["nnum"] = vo.nscannum;
            bbitem["nassistnum"] = vo.nscanastnum;
            bbitem["clocationid"] = vo.cinspaceid;
            var bbitems = [{
                "bbitem": bbitem
            }];
            item["bbitems"] = bbitems;
        }
        var items = [{
            "item": item
        }];
        var billinfo = {
            "head": head,
            "items": items
        };
        var billinfos = [{
            "billinfo": billinfo
        }];
        var isSuccess = TransInUtil.commitData(billinfos, json.pk_transinscan, function (data) {
            //更新提交数量 以及扫描数量 扫描数量去除提交数量
            //TransInUtil.updateBillAfterCommit(vo.cgeneralbid,vo.nscannum,vo.nscanastnum);
            //清空界面值
            doClear();
        });

    }

    function doClear() {
        var list = {};
        $ctx.push(list);
        $ctx.dataBind();
    }

    function onEventClick_showSpaceRef(sender, args) {
        var stordoc = $cache.read("defaultstockorg");
        if (stordoc == null || stordoc == "") {
            $alert("默认仓库不能为空，请设置！");
            return;
        }
        openRefPage("PDARACK", "cinspaceid_name", "cinspaceid", "pk_rack");

    }

// 打开参照页面
    function openRefPage(ncbillcode, ctxnamekey, ctxpkkey, pkfiel) {
        var jsonparam = {};
        getRefParam(ncbillcode, function (data) {
            jsonparam = data;
        });

        if (jsonparam == null) {
            //$alert("jsonparam is null!");
            return;
        }
        var stordoc = $cache.read("defaultstordoc");
        jsonparam["wheresql"] = " where pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";

        $view.open({
            viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
            isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
            data: jsonparam,
            callback: function () {
                var refdata = $param.getJSONObject("data");
                $ctx.put(ctxnamekey, refdata["name"]);
                $ctx.put(ctxpkkey, refdata[pkfiel]);
                $ctx.dataBind();
                $cache.write("default" + ctxnamekey, $jsonToString(refdata));

            }
        });
    }

    //获取参照vo的vo信息
    //reftype： 外系统调用标识
    function getRefParam(reftype, callback) {
        var condition = {
            "ncbillcode": reftype
        };
        NCMMPubUtil.queryVOByConditions(AppmappingheadVO, condition, function (data) {
            var jsondata = {
                bdlistdata: eval(data)
            };
            var reftitle = (jsondata.bdlistdata)[0]["appbillname"];
            if ((jsondata.bdlistdata)[0]["downloadnum"] == "" || (jsondata.bdlistdata)[0]["downloadnum"] == "0") {
                $alert("【" + reftitle + "】没有可参照的数据");
                if (callback != null && callback != undefined && typeof (callback) == 'function') {
                    callback(null);
                }
                return;
            }
            var reftablename = (jsondata.bdlistdata)[0]["apptablename"]; //本地表名
            var jsonparam = {
                reftype: reftype, //外系统调用标识
                reftitle: reftitle, //元数据显示名称
                reftablename: reftablename //本地表名
            };
            if (callback != null && callback != undefined && typeof (callback) == 'function') {
                callback(jsonparam);
            }
        });
    }

//货位编辑
    function com$yonyou$ncmm_pac_pda$TransInScanController$spaceEdit(sender, args) {
        var rack = $ctx.getString("cinspaceid_name");
        if (NCMMPubUtil.isEmpty(rack)) {
            $ctx.put("cinspaceid_name", "");
            $ctx.put("cinspaceid", "");
            $ctx.dataBind();
            return;
        }
        var wheresql = " where (code='" + rack + "' or name ='" + rack + "')";
        var stordoc = $cache.read("defaultstordoc");
        if (!NCMMPubUtil.isEmpty(stordoc)) {
            wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
        }
        getRackInfoByWhereSql(wheresql, rack, "cinspaceid", "cinspaceid_name");
    }

//货位scan
    function com$yonyou$ncmm_pac_pda$TransInScanController$spaceScan(sender, args) {
        $scanner.open({
            bindfield: "rack",
            callback: "rackScanBack()"
        });
    }

    function rackScanBack() {
        var rack = $ctx.getString("rack");
        var wheresql = " where code='" + rack + "'";
        var stordoc = $cache.read("defaultstordoc");
        if (!NCMMPubUtil.isEmpty(stordoc)) {
            wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
        }
        getRackInfoByWhereSql(wheresql, rack, "cinspaceid", "cinspaceid_name");
    }

    function getRackInfoByWhereSql(wheresql, rack, pkField, nameField) {
        if (NCMMPubUtil.isTableExist(RackVO) == false) {
            $alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
            $ctx.put(nameField, "");
            $ctx.put(pkField, "");
            $ctx.dataBind();
            return;
        }
        NCMMPubUtil.queryVO(RackVO, wheresql, function (data) {
            //2 打开扫描记录编辑界面
            if (NCMMPubUtil.isEmpty(data)) {
                $alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
                $ctx.put(nameField, "");
                $ctx.put(pkField, "");
                $ctx.dataBind();
                return;
            }
            var vos = eval(data);
            $ctx.put(nameField, vos[0].name);
            $ctx.put(pkField, vos[0].pk_rack);
            $ctx.dataBind();
        });
    }

    com.yonyou.ncmm_pac_pda.TransInScanController.prototype = {
        spaceScan: com$yonyou$ncmm_pac_pda$TransInScanController$spaceScan,
        spaceEdit: com$yonyou$ncmm_pac_pda$TransInScanController$spaceEdit,
        doCommit: com$yonyou$ncmm_pac_pda$TransInScanController$doCommit,
        saveScanInfo: com$yonyou$ncmm_pac_pda$TransInScanController$saveScanInfo,
        calAstNum: com$yonyou$ncmm_pac_pda$TransInScanController$calAstNum,
        calNum: com$yonyou$ncmm_pac_pda$TransInScanController$calNum,
        close: com$yonyou$ncmm_pac_pda$TransInScanController$close,
        doscan: com$yonyou$ncmm_pac_pda$TransInScanController$doscan,
        inputMarCode: com$yonyou$ncmm_pac_pda$TransInScanController$inputMarCode,
        onload: com$yonyou$ncmm_pac_pda$TransInScanController$onload,
        initialize: com$yonyou$ncmm_pac_pda$TransInScanController$initialize,
        evaljs: com$yonyou$ncmm_pac_pda$TransInScanController$evaljs
    };
    com.yonyou.ncmm_pac_pda.TransInScanController.registerClass('com.yonyou.ncmm_pac_pda.TransInScanController', UMP.UI.Mvc.Controller);
} catch (e) {
    $e(e);
}
